package csc.fresher.view;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import csc.fresher.entity.InterestRate;
import csc.fresher.service.CurrencyService;
import csc.fresher.service.InterestRateService;
import csc.fresher.service.PeriodTypeService;

@Component
@Scope("request")
public class SavingInterestChangeManagedBean {

	@Autowired
	InterestRateService interestRateService;

	@Autowired
	CurrencyService currencyService;

	@Autowired
	PeriodTypeService periodTypeService;

	private List<InterestRate> savingInterestRates;

	public List<InterestRate> getSavingInterestRates() {
		return savingInterestRates;
	}

	public void setSavingInterestRates(List<InterestRate> savingInterestRates) {
		this.savingInterestRates = savingInterestRates;
	}	

	@PostConstruct
	public void init2() {
		if (interestRateService != null) {
			savingInterestRates = interestRateService.getAllInterestRateByCurrencyID(1);
			if (savingInterestRates != null) {
				for (InterestRate i : savingInterestRates) {
					if (currencyService != null) {
						i.setCurrency(currencyService.getCurrencyByID(i
								.getCurrencyID()));
						System.out.println(i.getCurrencyID());
					} else {
						System.err.println("currency service is null");
					}
					if (periodTypeService != null) {
						i.setPeriodType(periodTypeService.getPeriodTypeByID(i
								.getPeriodTypeID()));
					} else {
						System.err.println("period service is null");
					}
				}
			}
		} else {
			System.err.println("interest rate service is null");
		}
	}
}
